package acm.天梯赛4;

import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while (sc.hasNext()) {
            long m1=sc.nextInt();
            long m2=sc.nextInt();
            sc.nextLine();
            String str=sc.nextLine();
            long r1=0;
            long r2=0;
            long r3=0;
            for (int i = 0; i < str.length(); i++) {
                switch (str.charAt(i)){
                    case 'A': r1=m1;break;
                    case 'B': r2=m2;break;
                    case 'C': m1=r3;break;
                    case 'D': m2=r3;break;
                    case 'E': r3=r1+r2;break;
                    case 'F': r3=r1-r2;break;
                }
            }
            System.out.println(m1+","+m2);
        }
    }
}
